package band.wukong.practice.springboot.boot.web.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wukong(wukonggg@139.com)
 */
//@ControllerAdvice(basePackages = "band.wukong.practice.springboot.boot.web.exception")
public class GlobalExceptionHandlerInJsonView {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Map<String, Object> handleException(Exception e) {
        Map<String, Object> ret = new HashMap<>();

        if (e instanceof ArithmeticException) {
            ret.put("code", "008");
//            ret.put("message", e.getMessage());
            ret.put("message", "全局-算数异常");
        } else {
            ret.put("code", "001");
//            ret.put("message", e.getMessage());
            ret.put("message", "全局-非算数异常");
        }
        return ret;
    }

}
